package com.inspur.attendance.Dao;

import com.inspur.attendance.Entity.Department;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


@Repository
public interface DepartmentDao extends JpaRepository<Department, Long> {

    // @Query(value = "delete from department where department_id = ${id}", nativeQuery = true)
    // public void delDepartment(@Param("id") Long id);

    @Transactional
    @Modifying
    @Query(value = "delete from department where department_id = ?1", nativeQuery = true)
    public void deleteByDepartmentId(Long id);

    @Transactional
    @Modifying
    @Query(value = "update department set total_user = total_user + 1 where department_id = ?1", nativeQuery = true)
    public void addUserTotal(String d);

    @Transactional
    @Modifying
    @Query(value = "update department set total_user = total_user - 1 where department_id = ?1", nativeQuery = true)
    public void delUserTotal(String d);


    Department findTopByDepartmentId(Long departmentId);
}
